package com.zzuli.demo01.dao;

import com.zzuli.demo01.pojo.User;
import com.zzuli.demo01.util.JDBCUtils;
import org.junit.Test;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * Created by IntelliJ IDEA.
 *
 * @author Zyh
 * @date 2020/9/23/0023 20:06
 */
public class UserDaoImpl implements UserDao{

    private User user = null;
    JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());

    @Override
    public User getUser(String username, String password) {

        String sql = "select * from user where username = ? and password = ?";

        try {
            user = template.queryForObject(sql,new BeanPropertyRowMapper<>(User.class) , username, password);
        } catch (DataAccessException e) {
            return null;
        }
        return user;
    }
    @Test
    public void test(){
        UserDaoImpl userDao = new UserDaoImpl();
        User user = userDao.getUser("2", "123");
        System.out.println(user);
    }


}
